<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$return['ischecklogin']=model('core/core')->checklogin('','',true);
	$return['list']=pdo_getall('jy_daibao_merch',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	foreach($return['list'] as &$item){
		$item['typetitle']=$this->merch_type[$item['type']];
		$item['teamtypetitle']=$this->teamtype[$item['teamtype']];
	}
	set_html('title','我的企业');
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=$_RQ['id'];
	if($id){
		$item=pdo_get('jy_daibao_merch',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['images']=json_decode($item['images'],true);
	}else{
		$item=array();
	}
	$item['pcd']=$item['pcd']?json_decode($item['pcd'],true):array('city'=>'');
	$item['upass']='';
	$return['item']=$item;
	$return['groups']=pdo_getall('jy_daibao_merch_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['merch_type']=$this->merch_type;
	$return['teamtype']=$this->teamtype;
	set_html('title','我的企业');
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['pcd']['province']){
			exi('城市不能为空！','error');
	}
	if(!$postdata['images']){
			//exi('图片不能为空！','error');
	}
	if(!$postdata['name']){
			exi('联系人姓名不能为空！','error');
	}
	if(!$postdata['title'] || !$postdata['mobile'] || !$postdata['codeimg'] || !$postdata['codesn']){
		exi('请先完善联系电话，企业名称，营业执照，执照编号！','error');
	}
	if(empty($postdata['lat_lng'])){
			//exi('请选择坐标！','error');
	}
	if($postdata['pcd']){
		if($postdata['pcd']['city']){
			if($postdata['pcd']['city']=='北京市' || $postdata['pcd']['city']=='上海市' || $postdata['pcd']['city']=='天津市'){
				$address=$postdata['pcd']['city'].' 市辖区';
			}else{
				$address=$postdata['pcd']['province'].' '.$postdata['pcd']['city'];
			}
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		}
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'desc'=>trim($postdata['desc']),
		'mid'=>intval($postdata['mid']),
		'content'=>trim($postdata['content']),
		'fname'=>trim($postdata['fname']),
		'name'=>trim($postdata['name']),
		'mobile'=>trim($postdata['mobile']),
		'address'=>trim($postdata['address']),
		'codesn'=>trim($postdata['codesn']),
		'codeimg'=>trim($postdata['codeimg']),
		'codeimg1'=>trim($postdata['codeimg1']),
		'codeimg2'=>trim($postdata['codeimg2']),
		'codename'=>trim($postdata['codename']),
		'banktitle'=>trim($postdata['banktitle']),
		'banksn'=>trim($postdata['banksn']),
		'status'=>intval($postdata['status']),
		'type'=>intval($postdata['type']),
		'pcd'=>ijson_encode($postdata['pcd']),
		'code'=>$code,
		'teamtype'=>intval($postdata['teamtype']),
		'groupid'=>intval($postdata['groupid']),
	);
	if($postdata['upass']){
		$data['upass']=base64_encode($postdata['upass']);
	}
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_daibao_merch',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_daibao_merch',$data);
	}
	if($_SESSION['os']=='windows'){
		exi('操作成功！','','goback');
	}else{
		exi('操作成功！','','/mymerch/');
	}
}
